<?php
if (!defined('IN_PHPBB'))
{
	exit;
}

class molten_chat_phpbb_hook
{
	function assign_template_vars()
	{
		global $phpEx, $phpbb_root_path, $template, $user;

		// This data will be configurable inside of the administrator control panel in the future.
		$parameters = array(
			'room' => 'system_index', // The name of the room.
			'levels' => 5, // The maximum levels stored on disk per room.
			'messages' => 50, // The maximum messages stored per level.
			'retrieve' => 100, // The maximum messages to retrieve for fresh sessions (this should not be more than [(levels - 1) * messages]).
			'age' => 300, // The maximum age (in seconds) of a level before it is deleted.
			'update' => 30 // The amount of time that must pass before an updated user list is sent if no more users join or leave the room.
		);

		// Set includes directory to the proper location.
		define('molten_chat_include', $phpbb_root_path . 'includes/molten_chat/', true);

		// Include chat program.
		require(molten_chat_include . 'molten_chat_server.' . $phpEx);

		// Add the language variables for the chat program to our environment.
		$user->add_lang('mods/molten_chat/display');

		// Create the room (if it doesn't exist).
		molten_chat_server::create($parameters['room']);

		// Connect to the room.
		molten_chat_server::connect($parameters['room'], false, false, $parameters['levels'], $parameters['messages'], $parameters['retrieve'], $parameters['age'], $parameter['update']);

		// Add template variables.
		$template->assign_vars(array(
			'MOLTEN_CHAT_POPOUT' => append_sid($phpbb_root_path . 'molten_chat_room.' . $phpEx, 'build', false),
			'MOLTEN_CHAT_RETRIEVE' => append_sid($phpbb_root_path . 'molten_chat_retrieve.' . $phpEx, 'build', false),
			'MOLTEN_CHAT_SEND' => append_sid($phpbb_root_path . 'molten_chat_send.' . $phpEx, 'build', false),
			'MOLTEN_CHAT_USERNAME' => $user->data['username']
		));
	}
}

$phpbb_hook->register('phpbb_user_session_handler', array('molten_chat_phpbb_hook', 'assign_template_vars'));
?>